package model

import (
	"time"
)

type IdModel struct {
	Id uint64 `grom:"type:bigint(20) unsigned primary_key" json:"id"`
}

func (m *IdModel) SetId(id uint64) {
	m.Id = id
}

func (m *IdModel) IsCreate() bool {
	return m.Id == 0
}

type DeletedModel struct {
	IdModel
	Deleted    int8       `json:"-" gorm:"type:tinyint(4);column:deleted;default:0"`
	DeleteTime *time.Time `json:"-" gorm:"type:datetime;column:delete_time"`
}

func (m *DeletedModel) LogicDelete() bool {
	return true
}

// 含有删除、创建字段模型
type CreateModel struct {
	DeletedModel
	CreateTime *time.Time `json:"createTime" gorm:"type:datetime;column:create_time;autoCreateTime"`
	CreatorId  uint64     `json:"creatorId" gorm:"type:bigint(20) unsigned;column:creator_id"`
	Creator    string     `json:"creator" gorm:"type:varchar(128);column:creator"`
}

// 基础实体模型，数据表最基础字段，尽量每张表都包含这些字段
type BaseModel struct {
	CreateModel

	UpdateTime *time.Time `json:"updateTime" gorm:"type:datetime;column:update_time;autoUpdateTime"`
	ModifierId uint64     `json:"modifierId" gorm:"type:bigint(20) unsigned;column:modifier_id"`
	Modifier   string     `json:"modifier" gorm:"type:varchar(128);column:modifier"`
}
